<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        // 基本解构
        var arr = [2, 45, 23, 80];
        var [a, b, c, d] = arr;
        console.log(a, b, c, d);//2 45 23 80

        var [a, b, c] = arr;
        console.log(a, b, c);//2 45 23

        // 可忽略解构
        var [a, , b] = [1, 2, 3];
        console.log(a, b);//1 3

        // 剩余运算符解构
        var [a, ...b] = [1, 2, 3, 4, 5];
        console.log(a, b);//1 [2, 3, 4, 5]

        //默认值
        var [a = 1, b = 2, c = 3] = [];
        console.log(a, b, c);//1 2 3

        var [a = 1, b = 2, c = 3, d = 4] = arr;
        console.log(a, b, c, d);//2 45 23 80

        var [a = 3, b = a] = [];     // a = 3, b = 3
        var [a = 3, b = a] = [1];    // a = 1, b = 1
        var [a = 3, b = a] = [1, 2]; // a = 1, b = 2

        //字符串解构
        var [a, b, c, d] = 'admin';
        console.log(a, b, c, d);//a d m i

        // 嵌套
        var arr = [2, 45, [23, 80]];
        var [a, b, c, d] = arr;
        console.log(a, b, c, d);//2 45 [23, 80]
    </script>
</body>

</html>